import api from '../../mock/index.js'
import { getGoodsById, createOrder } from '../../api/index.js'
	
const store = {
	state: {
		goods: {}, // 列表
	},
	
	mutations: {
		updateGoods(state, goods) {
			state.goods = goods
		},
	},
	
	actions: {
		// 通过id获取到产品
		async getGoodsById({ commit }, id = '') {
			let res = await api.post(getGoodsById, {
				id
			})
			commit('updateGoods', res.data)
		},
		
		async createOrder({ commit }, params = {}) {
			await api.post(createOrder, params)
		}
	},
	namespaced: true
}

export default store
